package com.onpositive.wikidataeditor;

import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPart;

import com.onpositive.semantic.model.api.changes.IValueListener;
import com.onpositive.semantic.model.api.changes.ObjectChangeManager;

public class PropertiesListView extends XMLViewWithRecourses
{
	public static final String ID = "com.onpositive.wikidataeditor.propertiesListView";
	
	public PropertiesListView() {
		super("dlf/properties-list.dlf");
		setSelectionProvider("lst");		
	}

	@Override
	public void createPartControl(Composite parent) {
		super.createPartControl(parent);
		getSelectionProvider();
		ObjectChangeManager.addWeakListener(Resources.getInstance(), new IValueListener<Object>(
				) {
			
			@Override
			public void valueChanged(Object oldValue, Object newValue) {
				getBinding("Group").refresh();
			}
		});
		getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(new ISelectionListener() {			

			@Override
			public void selectionChanged(IWorkbenchPart part, ISelection selection)
			{
				if (selection instanceof IStructuredSelection)
				{
					IStructuredSelection sl=(IStructuredSelection) selection;
				
					if( part.getTitle().equals("Property groups") )						
						getBinding("Group").setValue(sl.getFirstElement(), null);
				}
			}
		});
	}	

}